const App = getApp();
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderlist:[],
    state:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getdata();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  goinfo:function(e){
    var id = e.currentTarget.dataset['id'];

    wx.navigateTo({
      url: '/pages/order/qr?orderid='+id,
    })
  },
  goview:function(e){
    var id = e.currentTarget.dataset['id'];

    wx.navigateTo({
      url: '/pages/order/view?orderid='+id,
    })
  },
  getdata:function(){
    var state = this.data.state;
    var token = wx.getStorageSync('token');
    var that  = this;
    App._post_form('wxapi/myorder', {
      token:token,state:state
    }, function(result) {
      
        if(result.status=="200"){
          that.setData({orderlist:result.data})
        }
    });
  },
  onChange:function(e){
    console.log("ss",e.detail.name);
    this.setData({state:e.detail.name})
    this.getdata()
  },
  del:function(e){
    console.log("sssssss");
    var id = e.currentTarget.dataset['id'];
    var token = wx.getStorageSync('token');
    var that = this;
    Dialog.confirm({
      title: '删除预约记录',
      message: '您正在删除乘车预约记录，删除后将无法查看本条预约记录，确定删除吗？',
    })
      .then(() => {
        App._post_form('wxapi/order/del2', {
          token:token,id:id
        }, function(result) {
          
            if(result.status=="200"){
               
              wx.showToast({
                title: '操作成功',
                icon: 'succes',
                duration: 1000,
                mask:true
            })
              that.getdata()
                
            }
        });
        
        // on confirm
      })
      .catch(() => {
        // on cancel
      });
  }
})